import $ from "jquery";
import {url} from "../../util/config";
import {message} from "antd";
import login from "../login";
function getNewLogin(key) {
    return getRoleContent(key)
}
export default function getRoleContent(key) {
    console.log(key)
    let roles = [];
    let token = localStorage.getItem("token")

    $.ajax({
        async:false,
        headers: {
            'Accept': "application/json",
                'Authorization': token
        },
        url: url.api_url+`Role/GetRoleContent`,
        type: 'POST',
        contentType:"application/json",
        data: JSON.stringify(
             {
                 ROLE_ID:key
             }
        ),
        success: function(result) {
            if(result.result=="Token過期請重新登錄"){
                login(localStorage.getItem("account"), localStorage.getItem("password"));
                roles = getNewLogin(key)
            }else {
                console.log(result)
                let item = result.result
                let modulesId = item.ROLE_BIND_MODULEID_LIST.map(item=>{return item.MODULE_ID});
                if(item.ROLE_TYPE=="super"){
                    item.ROLE_TYPE = "manager"
                }
                roles = {
                    roleId:item.ROLE_ID,
                    roleName:item.ROLE_NAME,    //角色名称
                    roleDesc:item.ROLE_DESC,   //角色描述
                    roleType:item.ROLE_TYPE,  //角色类型
                    rolePermission:modulesId, //角色绑定的moduleId数组
                }
            }
        },
        error:function(error) {
            message.error("请求异常")
        }
    })
    return roles;

//  写ajax时把上面注释取消
//     return {
//         roleId:1,
//         roleName:"huahau",
//         roleType:"管理员",
//         roleDesc:"test",
//         rolePermission:[134, 231, 161, 162, 163, 216, 217, 218, 219, 220]
//     }

}
